<!--
 * @Description: 
 * @Version: 1.0
 * @Author: Yuanjy
 * @Date: 2020-03-09 20:41:17
 * @LastEditors: 任飞
 * @LastEditTime: 2020-07-08 10:02:52
 -->
<template>
  <div class="app-container">
    <eHeader :permissions="permissions" :company-levels="companyLevels" :id="data.id" :query="query"/>
    <!--表格渲染-->
    <el-table v-loading="loading" ref="table" :data="data" :tree-props="{children: 'children', hasChildren: 'hasChildren'}" row-key="id" border fit highlight-current-row>
      <el-table-column prop="settleDate" label="结算日期" />
      <el-table-column prop="userName" label="名称" />
      <el-table-column prop="userLevelName" label="级别" />
      <el-table-column prop="levelNum" label="级别数" />
      <el-table-column prop="totalLevelNum" label="总级别数" />
      <el-table-column prop="orderNum" label="销售订单数" />
      <el-table-column prop="totalOrderNum" label="总订单数" />
      <el-table-column prop="compName" label="所属公司" />
      <el-table-column prop="compProfitAmt" label="公司当期利润" />
      <el-table-column prop="saleBonus" label="销售应得分红" />
      <el-table-column prop="levelBonus" label="本级别应得分红" />
      <el-table-column prop="profitAmt" label="当期应得总分红" />
    </el-table>
    <el-pagination
      :total="total"
      :page-size="limit"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission' // 权限判断函数
import initData from '@/mixins/initData'
import treeTable from '@/components/TreeTable'
import { parseTime } from '@/utils/index'
import eHeader from './module/header'
import edit from './module/edit'
export default {
  components: { eHeader, edit, treeTable },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      sup_this: this,
      permissions: [],
      companyLevels: [],
      loading: true
    }
  },
  created() {
    this.getTypes()
    this.getLevels()
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    beforeInit() {
      this.url = '/admin/bonus/listPage'
      const query = this.query
      const value = query.value
      this.params = { pageNum: this.page, pageSize: this.limit, settleStatus: this.query.settleStatus, dateBegin: this.query.dateBegin, dateEnd: this.query.dateEnd, userName: this.query.userName }
      if (value) { this.params['name'] = value }
      return true
    },
    subDelete(id) {
      this.delLoading = true
      this.$api.fenxiao.company.del(id).then(res => {
        this.delLoading = false
        this.init()
        this.$notify({ title: '删除成功', type: 'success', duration: 2500 })
      }).catch(err => {
        this.delLoading = false
        console.log(err.response.data.message)
      })
    },
    getTypes() {
      this.$api.fenxiao.company.types("COMP_TYPE").then(res => {
        this.permissions = res.data
      })
    },
    getLevels() {
      this.$api.fenxiao.company.types("COMP_LEVEL").then(res => {
        this.companyLevels = res.data
      })
    }
  }
}
</script>

<style scoped>

</style>
